{include file="common/head"/}
<link rel="stylesheet" href="__STATIC__/plugins/spectrum/spectrum.css">
<script>
    var ADMIN = '__ADMIN__';
    var UPURL = "{:url('UpFiles/upImages')}";
    var PUBLIC = "__PUBLIC__";
    var imgClassName,fileClassName;
</script>
{include file="common/foot"/}
<script src="__STATIC__/common/js/jquery.2.1.1.min.js"></script>
<script>
    var edittext=new Array();
</script>
<script src="__STATIC__/ueditor/ueditor.config.js" type="text/javascript"></script>
<script src="__STATIC__/ueditor/ueditor.all.min.js" type="text/javascript"></script>

<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>{$title}</legend>
    </fieldset>
    <form class="layui-form" method="post" style="width: 1600px">
        {if condition="$info['id'] neq ''"}<input TYPE="hidden" name="id" value="{$info.id}">{/if}

        {volist name="fields" id="r"}
        {if condition="!empty($r['status'])"}
        <div class="layui-form-item">
            <label class="layui-form-label">{$r.name}</label>
            <div class="layui-input-4" id="box_{$r['field']}">
                {$r,input($r['field'])|getform=$form,###}
            </div>
        </div>
        {/if}
        {/volist}

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                {if condition="MODULE_NAME eq 'page'"}
                <a href="{:url('category/index')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
                {else /}
                <a href="{:url('index',['catid'=>input('catid')])}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
                {/if}
            </div>
        </div>
    </form>
</div>

<script src='__STATIC__/plugins/spectrum/spectrum.js'></script>
<script src='__ADMIN__/js/edit.js'></script>
<script>
    var thumb,pic,file;
    {if condition="ACTION_NAME=='add'"}
    var url= "{:url('insert')}";
    {else /}
        var url= "{:url('update')}";
        {/if}

            layui.use(['form','upload','layedit','laydate'], function () {
                var form = layui.form,upload = layui.upload,layedit = layui.layedit,laydate = layui.laydate;
                //缩略图上传
                upload.render({
                    elem: '#thumbBtn'
                    ,url: '{:url("UpFiles/upload")}'
                    ,accept: 'images' //普通文件
                    ,exts: 'jpg|png|gif' //只允许上传压缩文件
                    ,done: function(res){
                        $('#cltThumb').attr('src', "__PUBLIC__"+res.url);
                        $('#thumb').val(res.url);
                    }
                });
                //多图片上传
                var imagesSrc;
                upload.render({
                    elem: '#test2'
                    ,url: '{:url("UpFiles/upImages")}'
                    ,multiple: true
                    ,done: function(res){
                        $('#demo2 .layui-row').append('<div class="layui-col-md3"><div class="dtbox"><img src="__PUBLIC__'+ res.src +'" class="layui-upload-img"><input type="hidden" class="imgVal" value="'+ res.src +'"> <i class="delimg layui-icon">&#x1006;</i></div></div>');
                        imagesSrc +=res.src+';';
                    }
                });
                //日期
                laydate.render({
                    elem: '#addtime', //指定元素
                    type:'datetime',
                    format:'yyyy-MM-dd HH:mm:ss'
                });
                form.on('submit(submit)', function (data) {
                    if(edittext){
                        for (key in edittext){
                            data.field[key] = $(window.frames["LAY_layedit_"+edittext[key]].document).find('body').html();
                        }
                    }
                    var images='';
                    $(".imgVal").each(function(i) {
                        images+=$(this).val()+';';
                    });
                    data.field.images = images;
                    $.post(url, data.field, function (res) {
                        if (res.code > 0) {
                            layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                                location.href = res.url;
                            });
                        } else {
                            layer.msg(res.msg, {time: 1800, icon: 2});
                        }
                    });
                });
                $('.layui-row').on('click','.delimg',function(){
                    var thisimg = $(this);

                    layer.confirm('你确定要删除该图片吗？', function(index){
                        thisimg.parents('.layui-col-md3').remove();
                        layer.close(index);
                    })
                })
            });

</script>